<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>offsetLeft和offsetTop的值</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }

    #box{
      position: relative;
      margin-left: 100px;
      width: 500px;
      height: 500px;
      border: 10px solid blue;
      background-color: red;
    }
    #box #box1 {
      position: absolute;
      left: 50px;
      top: 50px;
      width: 300px;
      height: 300px;
      padding: 10px;
      overflow: scroll;
      border: 10px solid deepskyblue;
      background-color: green;
    }
    #box #box1 #box2{
      width: 500px;
      height: 500px;
      border: 13px solid purple;
      background-color: yellow;
    }
  </style>
</head>
<body>
  <div id="box">
    <div id="box1">
      <div id="box2"></div>
    </div>
  </div>
  <button>点击获取滚动的距离</button>

<script>
  
  var box = document.getElementById("box");
  var box1 = document.getElementById("box1");
  //拿到的是盒子边框大小
  console.log(box1.clientLeft);
  console.log(box1.clientTop)

  //拿到的是盒子的水平偏移量和垂直偏移量 其实就是拿的这个元素设置的定位left和top的值
  //离它最近的定位祖先元素的左上角
  console.log(box1.offsetLeft);
  console.log(box1.offsetTop);

  
  var btn = document.querySelector("button");
  btn.onclick = function () {
    //不需要加px
    console.log(box1.scrollLeft);
    console.log(box1.scrollTop);
    
  }
</script>
</body>
</html>